<template>
	<sl-page title=" " :navbarFixed="false">
		<!-- <view ref="sliderPage" class="slider-page">
			<view ref="scrollWrapper" class="scroll-wrapper" :style="dynamicStyle" @touchstart="handlerTouchStart"
				@touchmove="handlerTouchMove" @touchend="handlerTouchEnd">
				<view class="slider-item" v-for="(item, index) in members" :key="index">
					<view class="inner">
						{{item.name}}
						<Member :member="item"></Member>
					</view>
				</view>
			</view>
		</view> -->
		<uni-swiper-dot class="uni-swiper-dot-box" @clickItem=clickItem :info="info" :current="current" :mode="mode"
			:dots-styles="dotsStyles" field="content">
			<swiper class="swiper-box" @change="change" :current="swiperDotIndex">
				<swiper-item v-for="(item, index) in members" :key="index">
					<view class="member">
						<view class="member-head">
							<view class="head-image">
								<sl-image :value="item.image"></sl-image>
							</view>

							<view class="head-content">
								<view class="head-profile">
								</view>
								<view class="flex-column">
									<view class="py-1">
										{{item.name}}
									</view>
									<view class="">
										升级规则 >
									</view>
								</view>

							</view>
						</view>
						<view class="member-body">
							<view class="body-left">
							</view>
							<view class="body-center">
								<view class="center-hg">
									<sl-image :value="item.icon"></sl-image>
								</view>
								<view class="center-name">
									在获得200成长值可升级
								</view>
								<view class="center-point">
									<view class="point-name">
										成长值134/300
									</view>
									<view class="point-date">
										截止2024-04-22
									</view>
								</view>
								<view class="flex flex-x-center">
									<view class="bottom-line"></view>
								</view>
								<view class="flex-column flex-y-center">
									<view class="py-b-1">
										等级权益
									</view>
									<view class="center-box-one">
										升级奖励
										<view class="flex flex-x-center">
											<view class="px-1">
												成长值奖励
											</view>
											<view class="px-1">
												成长值倍率
											</view>
										</view>
									</view>
									<view class="center-box-two">
										会员礼包
										<view class="flex flex-x-center">
											<view class="px-1">
												优惠券
											</view>
											<view class="px-1">
												下单打折
											</view>
											<view class="px-1">
												下单包邮
											</view>
										</view>
									</view>
									<view class="center-box-three">
										积分权益
										<view class="flex flex-x-between">
											<view class="px-1">
												送积分
											</view>
											<view class="px-1">
												积分倍率
											</view>
											<view class="px-1">
												会员日双倍积分
											</view>
										</view>
										<view class="flex">
											<view class="px-1">
												生日双倍积分
											</view>
										</view>
									</view>
								</view>
							</view>
							<view class="body-right">
							</view>
						</view>
						<sl-flooter>
							<view class="btn-primary">{{member.price}} 付费升级</view>
						</sl-flooter>
					</view>
					<!-- <Member :member="item"></Member> -->
				</swiper-item>
			</swiper>
		</uni-swiper-dot>
	</sl-page>
</template>

<script>
	import MemberApi from '@/api/member/member.js';
	import Constants from '@/constants';
	import Member from '@/xj_user/member/components/member.vue';

	export default {
		//
		name: 'member',
		//
		mixins: [Constants],
		//
		components: {},
		//
		data() {
			return {
				startX: 0,
				pageIndex: 0,
				distanceX: 0,
				dynamicStyle: {
					transition: '',
					transform: '',
				},
				isMove: false,
				member: {},
				members: [],
				info: [{
						colorClass: 'uni-bg-red',
						url: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/shuijiao.jpg',
						content: '内容 A'
					},
					{
						colorClass: 'uni-bg-green',
						url: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/shuijiao.jpg',
						content: '内容 B'
					},
					{
						colorClass: 'uni-bg-blue',
						url: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/shuijiao.jpg',
						content: '内容 C'
					}
				],
				dotStyle: [{
						backgroundColor: 'rgba(0, 0, 0, .3)',
						border: '1px rgba(0, 0, 0, .3) solid',
						color: '#fff',
						selectedBackgroundColor: 'rgba(0, 0, 0, .9)',
						selectedBorder: '1px rgba(0, 0, 0, .9) solid'
					},
					{
						backgroundColor: 'rgba(255, 90, 95,0.3)',
						border: '1px rgba(255, 90, 95,0.3) solid',
						color: '#fff',
						selectedBackgroundColor: 'rgba(255, 90, 95,0.9)',
						selectedBorder: '1px rgba(255, 90, 95,0.9) solid'
					},
					{
						backgroundColor: 'rgba(83, 200, 249,0.3)',
						border: '1px rgba(83, 200, 249,0.3) solid',
						color: '#fff',
						selectedBackgroundColor: 'rgba(83, 200, 249,0.9)',
						selectedBorder: '1px rgba(83, 200, 249,0.9) solid'
					}
				],
				modeIndex: -1,
				styleIndex: -1,
				current: 0,
				mode: 'default',
				dotsStyles: {},
				swiperDotIndex: 0
			};
		},
		//
		onLoad() {
			this.loadPage();
		},
		onShow() {
			// this.$nextTick(() => {
			// 	const query = uni.createSelectorQuery().in(this);
			// 	query.select('.slider-page').boundingClientRect(data => {
			// 		console.log('data', data.width);
			// 	}).exec();
			// });
		},
		//
		methods: {
			//加载订单（个人）
			loadPage: async function() {
				try {
					const res = await MemberApi.buyables();
					console.log('【获取会员数据】:', res.obj);
					this.member = res.obj[0];
					this.members = res.obj;
					// this.dynamicStyle.width = uni.getSystemInfoSync().screenWidth * this.members.length;
				} catch (error) {
					console.error('【获取会员失败】:', error);
				}
			},
			//
			handlerTouchStart(e) {
				this.startX = e.touches[0].clientX;
				// console.log('this.startX: ', this.startX);
			},
			//
			handlerTouchMove(e) {
				const moveX = e.touches[0].clientX;
				// console.log('this.moveX: ', moveX);
				if (moveX > this.startX && this.pageIndex === 0 || moveX < this.startX && this.pageIndex === this.members
					.length - 1) {
					return
				}
				this.distanceX = moveX - this.startX;
				this.setTranslateX(-uni.getSystemInfoSync().screenWidth * this.pageIndex + this.distanceX);
				this.isMove = true;
			},
			//
			handlerTouchEnd() {
				if (this.isMove) {
					// console.log('this.distanceX: ',this.distanceX);
					if (Math.abs(this.distanceX) >= uni.getSystemInfoSync().screenWidth / 3) {
						// console.log('this.distanceX: ',this.distanceX);
						if (this.distanceX > 0) {
							this.pageIndex--
						}
						if (this.distanceX < 0) {
							this.pageIndex++
						}
					}
					// console.log('this.pageIndex: ',-this.pageIndex * 360);
					this.setTranslateX(-this.pageIndex * uni.getSystemInfoSync().screenWidth)
				}
				this.startX = 0
				this.distanceX = 0
				this.isMove = false;
			},
			setTranslateX(transX) {
				this.dynamicStyle.transition = 'all .1s';
				this.dynamicStyle.transform = 'translateX(' + transX + 'px)';
				// console.log('this.dynamicStyle: ', this.dynamicStyle);
			},
			change(e) {
				this.current = e.detail.current
			},
			selectStyle(index) {
				this.dotsStyles = this.dotStyle[index]
				this.styleIndex = index
			},
			selectMode(mode, index) {
				this.mode = mode
				this.modeIndex = index
				this.styleIndex = -1
				this.dotsStyles = this.dotStyle[0]
			},
			clickItem(e) {
				this.swiperDotIndex = e
			},
			onBanner(index) {
				console.log(22222, index);
			}
		}
	};
</script>

<style lang="scss" scoped>
	.slider-page {
		position: relative;
		display: flex;
		flex-direction: column;
		height: 100%;
		width: 100%;
		overflow: hidden;
	}

	.scroll-wrapper {
		display: flex;
		position: absolute;
		width: 1080px;
		height: 100%;
		flex-direction: row;
	}

	.slider-item {
		display: flex;
		width: 100%;
		height: 100%;
		flex: 1;

		.inner {
			display: flex;
			width: 100%;
			height: 100%;
			// justify-content: center;
			font-size: 100rpx;
		}
	}

	.swiper-box {
		height: 200px;
	}

	.swiper-item {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: center;
		align-items: center;
		height: 200px;
		color: #fff;
	}

	.swiper-item0 {
		background-color: #cee1fd;
	}

	.swiper-item1 {
		background-color: #b2cef7;
	}

	.swiper-item2 {
		background-color: #cee1fd;
	}

	.image {
		width: 750rpx;
	}

	/* #ifndef APP-NVUE */
	::v-deep .image img {
		-webkit-user-drag: none;
		-khtml-user-drag: none;
		-moz-user-drag: none;
		-o-user-drag: none;
		user-drag: none;
	}

	/* #endif */

	@media screen and (min-width: 500px) {
		.uni-swiper-dot-box {
			width: 400px;
			margin: 0 auto;
			margin-top: 8px;
		}

		.image {
			width: 100%;
		}
	}

	.uni-bg-red {
		background-color: #ff5a5f;
	}

	.uni-bg-green {
		background-color: #09bb07;
	}

	.uni-bg-blue {
		background-color: #007aff;
	}

	.example-body {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		padding: 20rpx;
	}

	.example-body-item {

		flex-direction: row;
		justify-content: center;
		align-items: center;
		margin: 15rpx;
		padding: 15rpx;
		height: 60rpx;
		/* #ifndef APP-NVUE */
		display: flex;
		padding: 0 15rpx;
		/* #endif */
		flex: 1;
		border-color: #e5e5e5;
		border-style: solid;
		border-width: 1px;
		border-radius: 5px;
	}

	.example-body-item-text {
		font-size: 28rpx;
		color: #333;
	}

	.example-body-dots {
		width: 16rpx;
		height: 16rpx;
		border-radius: 50px;
		background-color: #333333;
		margin-left: 10rpx;
	}

	.active {
		border-style: solid;
		border-color: #007aff;
		border-width: 1px;
	}

	.member {
		font-size: $uni-font-size-base;
		color: $uni-text-color-primary;

		.member-head {
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			// height: 444rpx;

			.head-image {
				display: flex;
				width: 100%;
				height: 380rpx;
				position: relative;
			}


			.head-profile {
				// position: relative;
				width: 104rpx;
				height: 104rpx;
				border-radius: 50%;
				overflow: hidden;
				border: 2rpx solid #CCCCCC;
				margin-right: 18rpx;
			}

			.head-content {
				display: flex;
				position: absolute;
				top: 140rpx;
				left: 88rpx;
				color: rgba(255, 255, 255, 1);
			}
		}

		.member-body {
			display: flex;
			justify-content: space-between;
			width: 100%;
			height: 1100rpx;
			position: relative;
			top: 90px;

			.body-left {
				flex-basis: 3%;
				height: 100%;
				background-color: white
			}

			.body-center {
				flex-basis: 84%;
				background-color: white;
				position: relative;
				align-items: center;

				.center-hg {
					position: absolute;
					width: 122rpx;
					height: 104rpx;
					top: 46rpx;
					left: 444rpx;
				}

				.center-name {
					margin-top: 98rpx;
					margin-left: 34rpx;
					color: #999;
					font-size: 12px;
					line-height: 20px;
				}

				.center-point {
					display: flex;
					// justify-content: space-around;
					margin-left: 34rpx;
					margin-top: 64rpx;

					.point-name {
						color: #F7441D;
						font-size: 12px;
						line-height: 20px;
					}

					.point-date {
						color: #999;
						font-size: 10px;
						margin-left: 200rpx;
						line-height: 20px;
					}
				}

				.center-box-one {
					width: 279px;
					height: 110px;
					flex-shrink: 0;
					background: #F6F6F6;
					text-align: center;
					padding-top: 20rpx;
					font-size: 12px;
				}

				.center-box-two {
					width: 279px;
					height: 110px;
					flex-shrink: 0;
					background: #F3F3F3;
					margin-top: 10rpx;
					text-align: center;
					padding-top: 20rpx;
					font-size: 12px;
				}

				.center-box-three {
					width: 279px;
					height: 110px;
					flex-shrink: 0;
					background: #F3F3F3;
					margin-top: 10rpx;
					text-align: center;
					padding-top: 20rpx;
					font-size: 12px;
					padding: 0rpx 24rpx;
				}

			}

			.body-right {
				flex-basis: 3%;
				height: 100%;
				background-color: white
			}
		}

		.sl_image {
			position: absolute;
			width: 100%;
			height: 100%;
			max-width: 100%;
			max-height: 100%;
			top: 0;
			left: 0;
		}

		.head-top {
			position: absolute;
			top: 80rpx;
			left: 88rpx;
		}
	}
</style>